<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	静默签署授权API----接口顺序排列封装
 * 
 */


$appId = "7438873193";       //应用id
$secret = "1dc4d84aeeb9698c29c57202485581b5";  //应用密钥
$grantType = "client_credentials";   //授权类型，固定值
$url = "https://smlopenapi.esign.cn";  // url沙箱环境

$token = getTokenEnd($appId,$secret,$grantType);  // 直接返回token值


$header = array(                          // header请求头信息
        'X-AjaxPro-Method:ShowList',
        'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36',
        'X-Tsign-Open-App-Id:'.$appId,
		'Content-Type:application/json',
		'charset=UTF-8',
		'X-Tsign-Open-Token:'.$token
    );

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [setsignAuth 根据个人/机构签署账号ID设置静默签署授权]    有用    send_request
 * 签署用户（个人/企业）如果需要自动盖章签署时，需要先通过该接口完成静默签署授权。
 * @param  [type] $accountId [个人/机构签署账号ID，通过创建个人/机构签署账号接口获取]
 * @param  [type] $deadline  [授权截止时间, 格式为yyyy-MM-dd HH:mm:ss，默认无限期]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回成功]
 */
function setsignAuth($accountId,$deadline,$header,$url="https://smlopenapi.esign.cn"){
	$get_url = $url."/v1/signAuth/".$accountId;
	$data = [
		'accountId'=>$accountId,
		"deadline"=>$deadline
	];
	$header = $header;
	$res = send_request($get_url, $method = "POST", $data, $header);
	return $res['data'];
}
// $accountId = "a7070967395447c884c1715063b6aac7";
// $deadline = '2021-09-26 11:00:00';
// $a = setsignAuth($accountId,$deadline,$header);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [deletesignAuth 根据个人/机构签署账号ID解除静默签署授权]   有用    curlData
 * @param  [type] $accountId [个人/机构签署账号ID，通过创建个人/机构签署账号接口获取]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回成功]
 */
function deletesignAuth($accountId,$header,$url="https://smlopenapi.esign.cn"){
	$url = $url."/v1/signAuth/".$accountId;
	$header = $header;
	$res = curlData($url, $data='', $header, $method = 'DELETE', $type='json');
	return $res;
}
// $accountId = "a7070967395447c884c1715063b6aac7";
// $a = deletesignAuth($accountId,$header);
// var_dump($a);die;



